package com.symria.server.bo.system;

import java.util.Date;

import com.symria.framework.page.Page;
import com.symria.framework.util.MD5Util;
import com.symria.server.bo.common.CommonService;
import com.symria.server.dao.common.AdminDao;
import com.symria.server.po.CustomInfo;
import com.symria.server.po.IosChannelConfig;
import com.symria.server.po.UserAccount;
import com.symria.server.po.UserInfo;
import com.symria.system.constants.ATTSystem;

public class AdminService extends CommonService {
    private AdminDao adminDao;
    
    
    
	public AdminDao getAdminDao() {
		return adminDao;
	}


	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}



	public void saveUserInfo(UserInfo user){
	    if(user!=null){
	    	user.setRoleId(ATTSystem.CHANNEL_ROLE_ID);
	    	user.setCreateDate(new Date());
	    	user.setStatus(ATTSystem.LOGIC_TRUE);
	    	user.setPassword(new MD5Util().getMD5ofStr("123456"));
	    	saveObject(user);
	    	
	    	UserAccount ua = new UserAccount();
	    	ua.setUserId(user.getUserId());
	    	ua.setGetMoney(0d);
	    	ua.setPayMoney(0d);
	    	ua.setFirMonthMoney(0d);
	    	saveObject(ua);
	    	
	    	IosChannelConfig config = new IosChannelConfig();
	    	config.setStatus(ATTSystem.LOGIC_FALSE);
	    	config.setUserId(user.getUserId());
	    	config.setAppId("appid");
	    	config.setMac("mac");
	    	config.setIdfa("idfa");
	    	config.setCallBack("callback");
	    	saveObject(config);
	    }	
	}
	
	public void updateUserInfo(UserInfo ou,UserInfo nu){
	    	ou.setCompanyName(nu.getCompanyName());
	    	ou.setRealName(nu.getRealName());
	    	ou.setCompanyAddress(nu.getCompanyAddress());
	    	ou.setMobile(nu.getMobile());
	    	ou.setContact(nu.getContact());
	    	ou.setRealName(nu.getRealName());
	    	ou.setPhone(nu.getPhone());
	    	updateObject(ou);
	}
	public boolean haveUser(String username){
		return adminDao.haveUser(username);
	}
	
	public void searchChannel(UserInfo user,Page page){
		adminDao.searchChannel(user, page);
	}
	
	public void saveCustom(CustomInfo c){
		c.setCreateDate(new Date());
		adminDao.saveObject(c);
	}
	public void updateCustom(CustomInfo oc,CustomInfo nc){
		oc.setComName(nc.getComName());
		oc.setCallUser(nc.getCallUser());
		oc.setComDesc(nc.getComDesc());
		oc.setEmail(nc.getEmail());
		oc.setMobile(nc.getMobile());
		oc.setTax(nc.getTax());
		adminDao.updateObject(oc);
	}
	public void searchCustomInfo(CustomInfo c,Page page){
		adminDao.searchCustomInfo(c, page);
	}
	
	
}
